/**
 * CategoryModel
 * @Chunning.Xu
 * 2011 Nov 22, 2011 3:20:45 PM
 **/
package com.lux.product.models
{
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;

	[Event(name="complete", type="flash.events.Event")]
	public class CategoryModel extends GeneralModel
	{
		//START.
		
		private var loader:Loader;
		
		public var title:String;
		
		public var asset:String;
		public var assetSWF:Object;
		public var swfLoaded:Boolean;
		
		public var series:Vector.<SeriesModel>;
		
		public function CategoryModel()
		{
		}
		
		private function swfLoadedHandler(evt:Event):void
		{
			var loader:Loader = (evt.currentTarget as LoaderInfo).loader;
			assetSWF = loader.content;
			swfLoaded = true;

			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,swfLoadedHandler);
			loader = null;	
			
			series = new Vector.<SeriesModel>;
			for each(var sXML:XML in xml["series"])
			{
				var seriesModel:SeriesModel = new SeriesModel;
				series.push(seriesModel);
				seriesModel.setXML(sXML);
			}
			
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		public override function setXML(xml:XML):void
		{
			this.xml = xml;
			title = xml["@title"].toString();
			asset = xml["@asset"].toString();
			
			loader = new Loader;
			loader.load(new URLRequest(asset),new LoaderContext(true,ApplicationDomain.currentDomain));
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,swfLoadedHandler);
		}
		
		//END
	}
}